package com.sinya.shoppingmall.utils;

import android.support.v4.widget.SlidingPaneLayout;
import android.view.MotionEvent;
import android.view.View;

/**
 * @author KoizumiSinya
 * @date 2016/1/14.
 */
public class TouchUtils {

    /**
     * 设置该控件不会与SlidingPaneLayout 侧滑冲突
     * @param mSlidingPaneLayout
     * @param view
     */
    public static void sideTouchLose(final SlidingPaneLayout mSlidingPaneLayout, View view) {
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int act = event.getAction();
                if (act == MotionEvent.ACTION_DOWN) {
                    // 处理侧滑冲突的问题
                    if (mSlidingPaneLayout != null) {
                        mSlidingPaneLayout.requestDisallowInterceptTouchEvent(true);
                    }

                } else if (act == MotionEvent.ACTION_UP) {
                    // 处理侧滑冲突的问题
                    if (mSlidingPaneLayout != null) {
                        mSlidingPaneLayout.requestDisallowInterceptTouchEvent(false);
                    }
                }

                return false;
            }
        });
    }
}
